﻿using Framework.EncryptionDecryptionService.Abstract;
using Framework.EncryptionDecryptionService.Attributes;
using Framework.EncryptionDecryptionService.Enums;
using Framework.EncryptionDecryptionService.Models;
using System.Security.Cryptography;

namespace Framework.EncryptionDecryptionService.Achieve
{
    /// <summary>
    /// RSA秘钥服务
    /// </summary>
    [Encryption(EncryptionAlgorithm.RSA)]
    public class SecretKeyServiceRsa : AbsSecretKeyService
    {
        /// <summary>
        /// RSA秘钥服务
        /// </summary>
        /// <param name="secretKey">秘钥</param>
        public SecretKeyServiceRsa(SecretKeyModel secretKey = null) : base(secretKey)
        {
        }

        internal override SecretKeyModel InitStaticSecretKey()
        {
            using (RSA rsa = RSA.Create(2048))
            {
                return new SecretKeyModel(rsa.ToXmlString(true), rsa.ToXmlString(false));
            }
        }
    }
}
